//
//  BannerVeiwCell.swift
//  UILbrary
//
//  Created by 斌 on 2017/8/8.
//  Copyright © 2017年 mac. All rights reserved.
//

import UIKit
import SnapKit
let titleLableHeight:CGFloat = 20.0

class BannerVeiwCell: UICollectionViewCell {
    // 轮播图 图片
    var bannerImage:UIImageView?
    // 轮播图 标题
    var titleLabel:UILabel?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.configUI()
    }
    
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
    }
    
    func configUI(){
        // 所有控件都采用 自动布局. (暂时使用绝对布局)
        // 添加轮播图片
        
        bannerImage = UIImageView.init(frame:CGRect.zero)
        bannerImage?.backgroundColor = UIColor.red
        self.contentView.addSubview(bannerImage!)
        // 自动布局
        
        // 添加轮播图标题
        titleLabel = UILabel.init(frame:CGRect.zero)
        titleLabel?.textAlignment = .center
        titleLabel?.backgroundColor = UIColor.blue
        self.contentView.addSubview(titleLabel!)
        bannerImage?.snp.makeConstraints({ (make) in
            make.top.equalTo(self.contentView)
            make.left.equalTo(self.contentView)
            make.right.equalTo(self.contentView)
            make.bottom.equalTo(self.contentView).offset(-titleLableHeight)
        })
        
        self.titleLabel?.snp.makeConstraints({ (make) in
            make.height.equalTo(titleLableHeight)
            make.left.right.equalTo(self.bannerImage!)
            make.bottom.equalTo(self.contentView)
        })
    }
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
    }
    /// 调整 子视图的 约束
    func adjustmentConstraints(){
        if self.titleLabel?.isHidden==true{
            self.bannerImage?.snp.remakeConstraints({ (make) in
                make.top.left.right.bottom.equalTo(0)
            })
        }
    }
}

